//
//  HJZRetweetStatusView.m
//  HJZWeiBo
//
//  Created by 蒋晨成 on 16/6/1.
//  Copyright © 2016年 蒋晨成. All rights reserved.
//

#import "HJZRetweetStatusView.h"
#import "HJZPhotosView.h"
#import "HJZStatusFrame.h"
#import "RCLabel.h"
#import "HtmlString.h"
#import "UIImage+Extend.h"

@interface HJZRetweetStatusView ()<RCLabelDelegate>

/** 转发微博正文 */
@property (nonatomic, weak) RCLabel *retweetContentLabel;
/** 转发微博配图 */
@property (nonatomic, weak) HJZPhotosView *retweetPhotoView;
@end

@implementation HJZRetweetStatusView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.userInteractionEnabled = YES;
        self.image = [UIImage resizedImageWithName:@"timeline_retweet_background"];
        
       
        
        // 2. 正文
        RCLabel *retweetContentLabel = [[RCLabel alloc] init];
        retweetContentLabel.delegate = self;
        retweetContentLabel.font = [UIFont systemFontOfSize:HJZStatusContentFont];
        retweetContentLabel.textColor = COLOR(90, 90, 90, 1);
        retweetContentLabel.lineBreakMode = NSLineBreakByCharWrapping;
        [self addSubview:retweetContentLabel];
        self.retweetContentLabel = retweetContentLabel;
        
        // 3. 配图
        HJZPhotosView *retweetPhotoView = [[HJZPhotosView alloc] init];
        [self addSubview:retweetPhotoView];
        self.retweetPhotoView = retweetPhotoView;
    }
    return self;
}

#pragma mark - 设置数据

- (void)setStatusFrame:(HJZStatusFrame *)statusFrame
{
    _statusFrame = statusFrame;
    
    HJZStatus *retweetStatus = statusFrame.status.retweeted_status;
    
    
    
    // 正文
    NSString *retContentString = [NSString stringWithFormat:@"@%@:%@",  retweetStatus .user.name, retweetStatus.text];
    
    NSString *str = [HtmlString transformString:retContentString];
    self.retweetContentLabel.componentsAndPlainText = [RCLabel extractTextStyle:str];
    self.retweetContentLabel.frame = statusFrame.retweetContentLabelF;
    // 配图
    if (retweetStatus.pic_urls.count) {
        self.retweetPhotoView.hidden = NO;
        
        self.retweetPhotoView.photos = retweetStatus.pic_urls;
        
        self.retweetPhotoView.frame = statusFrame.retweetPhotoViewF;
    } else {
        self.retweetPhotoView.hidden = YES;
    }
}

#pragma mark --- RCLabel代理方法 ---
- (void)RCLabel:(id)RCLabel didSelectLinkWithURL:(NSString *)url {
    
    if ([self.delegate respondsToSelector:@selector(retweenStatusViewClickWithUrl:)]) {
        [self.delegate retweenStatusViewClickWithUrl:url];
    }
    
}
@end
